//
//  ViewController.m
//  QQ12星座
//
//  Created by dllo on 16/7/25.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "ViewController.h"
#import "YMJCoverFlow.h"
#import "YMJCollectionViewCell.h"
@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collect;
@property (nonatomic, strong) NSMutableArray *array;
@property (nonatomic, strong) NSMutableArray *nameArray;
@property (nonatomic, strong) NSMutableArray *dateArray;
@end

@implementation ViewController
// 如果tableHeadView要进行修改,必须加上beginUpdates 和endUpdates
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    YMJCoverFlow *flowLayout = [[YMJCoverFlow alloc] init];
    flowLayout.itemSize = CGSizeMake(72, 105);
    flowLayout.minimumLineSpacing = 4;
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collect = [[UICollectionView alloc] initWithFrame:CGRectMake(17.5, 205, 414 - 35, 175) collectionViewLayout:flowLayout];
    [self.view addSubview:_collect];
    self.collect.delegate = self;
    self.collect.dataSource = self;
    _collect.backgroundColor = [UIColor brownColor];
    self.collect.showsHorizontalScrollIndicator = NO;
    [_collect registerClass:[YMJCollectionViewCell class] forCellWithReuseIdentifier:@"1"];
    self.array = [NSMutableArray arrayWithObjects:@"shuiping", @"shuangyu", @"baiyang", @"jinniu", @"shuangzi", @"juxie", @"shizi", @"chunv", @"tianping", @"tianxie", @"sheshou", @"mojie", nil];
    self.nameArray = [NSMutableArray arrayWithObjects:@"水瓶座", @"双鱼座", @"白羊座", @"金牛座", @"双子座", @"巨蟹座", @"狮子座", @"处女座", @"天秤座", @"天蝎座", @"射手座", @"摩羯座", nil];
    self.dateArray = [NSMutableArray arrayWithObjects:@"1/20-2/18", @"2/19-3/20", @"3/21-4/19",@"4/20-5/20", @"5/21-6/21", @"6/22-7/22", @"7/23-8/22", @"8/23-9/22", @"9/23-10/23", @"10/24-11/22", @"11/23-12/21", @"12/22-1/19", nil];
    [self.array insertObject:@"mojie" atIndex:0];
    [self.array insertObject:@"sheshou" atIndex:0];
    [self.array insertObject:@"tianxie" atIndex:0];
    [self.array insertObject:@"tianping" atIndex:0];
    [self.array addObject:@"shuiping"];
    [self.array addObject:@"shuangyu"];
    [self.array addObject:@"baiyang"];
    [self.array addObject:@"jinniu"];
    [self.nameArray insertObject:@"摩羯座" atIndex:0];
    [self.nameArray insertObject:@"射手座" atIndex:0];
    [self.nameArray insertObject:@"天蝎座" atIndex:0];
    [self.nameArray insertObject:@"天秤座" atIndex:0];
    [self.nameArray addObject:@"水瓶座"];
    [self.nameArray addObject:@"双鱼座"];
    [self.nameArray addObject:@"白羊座"];
    [self.nameArray addObject:@"金牛座"];
    [self.dateArray insertObject:@"12/22-1/19" atIndex:0];
    [self.dateArray insertObject:@"11/23-12/21" atIndex:0];
    [self.dateArray insertObject:@"10/24-11/22" atIndex:0];
    [self.dateArray insertObject:@"9/23-10/23" atIndex:0];
    [self.dateArray addObject:@"1/20-2/18"];
    [self.dateArray addObject:@"2/19-3/20"];
    [self.dateArray addObject:@"3/21-4/19"];
    [self.dateArray addObject:@"4/20-5/20"];
    _collect.contentOffset = CGPointMake(302.666667, 0);

}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 12 + 8;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    YMJCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"1" forIndexPath:indexPath];
    cell.label.text = _nameArray[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:self.array[indexPath.row]];
    cell.dateLabel.text = self.dateArray[indexPath.row];
    return cell;
}
// 缺点无法点击跳转下一个cell
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
   
    if (_collect.contentOffset.x == 0) {
        _collect.contentOffset = CGPointMake(910.666667, 0);
    }
    else if (_collect.contentOffset.x == 1137.000000) {
        _collect.contentOffset = CGPointMake(226.333333, 0);
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
